﻿using HealthcareSystem.API.Read.Application.Command.Disease;
using HealthcareSystem.API.Read.Application.Command.Element.ElementCommand;
using HealthcareSystem.API.Read.DTO.Disease;
using HealthcareSystem.API.Read.DTO.Element;
using HealthcareSystem.Domain.BasicSettings.Diseasemanagement;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Read.Application.CommandHandel.Disease
{
    public class SelectListofdiseasesCommandHandel : IRequestHandler<SelectListofdiseasesCommand, ApiResult<List<SelectListofdiseasesDto>>>
    {
        IBaseRepository<Listofdiseases> listofdiseasesHandel;

        public SelectListofdiseasesCommandHandel(IBaseRepository<Listofdiseases> listofdiseasesHandel)
        {
            this.listofdiseasesHandel = listofdiseasesHandel;
        }
        /// <summary>
        /// 病种下拉框处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<SelectListofdiseasesDto>>> Handle(SelectListofdiseasesCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<SelectListofdiseasesDto>> result = new ApiResult<List<SelectListofdiseasesDto>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();

            var list = from a in listofdiseasesHandel.GetAll()
                       select new SelectListofdiseasesDto
                       {
                           ListofdiseasesId = a.ListofdiseasesId,
                           ListofdiseasesName = a.ListofdiseasesName,
                       };

            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
